package day6.Component;



import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;

public class TestJDialog extends JFrame{
	int w = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
	int h = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
	public TestJDialog(String title) {
		this.setTitle(title);
		this.setSize(400, 500);
		//this.setLocationRelativeTo(null);
		
		this.setLocation((w-this.getWidth())/2, (h-this.getHeight())/2);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		
		
		// 放到最后显示窗口  
		this.setVisible(true);
		initComponent();
	}
	// 初始化
	private void initComponent() {
		/*
		 * 对话框组件 
		 * @parm1: owner 对话框出现在哪个窗口上
		 * @parm2: title: 标题
		 * @parm3: modal: 是否能点击外部窗口 
		 * 			true不能点击 false可以点击
		 */
		
		JDialog dialog = new JDialog(this, "消息", true);
		dialog.setSize(200,200);
		dialog.setLocation((w-dialog.getWidth())/2, (h-dialog.getHeight())/2);
		JButton button = new JButton("点击一下");
		//MyMouseListener l = new MyMouseListener(dialog);
		//给事件源绑定监听器
		button.addMouseListener(new MouseAdapter() {

			@Override
			public void mouseClicked(MouseEvent e) {
				dialog.setVisible(true);
			}
			
			
		});
		this.add(button);
		//dialog.setVisible(true);
	}

	public static void main(String[] args) {
		new TestJDialog("对话框");
	}
}

//自定义鼠标实现类 
//适配器
//class MyMouseListener implements MouseListener{
//class MyMouseListener extends MouseAdapter{
//	private JDialog dialog;
//	public MyMouseListener(JDialog dialog) {
//		this.dialog = dialog;
//	}
//
//	@Override   //鼠标点击方法  根据自己的 逻辑   // 弹框出现
//	public void mouseClicked(MouseEvent e) {
//		dialog.setVisible(true);
//	}

//	@Override
//	public void mousePressed(MouseEvent e) {
//		//鼠标按压
//	}
//
//	@Override
//	public void mouseReleased(MouseEvent e) {
//		
//	}
//
//	@Override
//	public void mouseEntered(MouseEvent e) {
//		//鼠标进入
//	}
//
//	@Override
//	public void mouseExited(MouseEvent e) {
//		//鼠标移开
//	}
//	



